package com.lanou3g.HW_0521.controller;

import com.lanou3g.HW_0521.model.LoginModel;
import com.lanou3g.HW_0521.pojo.User;
import com.lanou3g.HW_0521.util.JDBCUtil;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/5/19;
 * Otherwise, I don't know who created it either
 */

public class LoginController {
    private LoginModel loginModel = new LoginModel();

    public User login(String username, String password) {

        try {
            JDBCUtil.begin();

            if (username == null || password == null) {
                return null;
            }

            if (!loginModel.canLogin(username, password)) {
                return null;
            }
            User user = loginModel.login(username, password);

            return user;

        } finally {

            JDBCUtil.closeConn();
        }
    }
}
